package com.yanqu.road.server.cmd.activity.recallplayer;


import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_RECALL_PLAYER_UPDATE_USER_INFO_FROM_CROSS, desc = "跨服来本服拿绑定玩家数据")
public class UpdateBindUserInfoFromCrossCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        RecallPlayerProto.RecallPlayerGetServerUserInfoReq reqMsg = RecallPlayerProto.RecallPlayerGetServerUserInfoReq.parseFrom(yanQuMessage.getBytes());
        RecallPlayerProto.RecallPlayerGetUserInfoResp.Builder builder = RecallPlayerProto.RecallPlayerGetUserInfoResp.newBuilder();
        builder.setFromUserId(reqMsg.getFromUserId());
        builder.setFromUserServer(reqMsg.getFromUserServer());
        builder.setRecallUserId(reqMsg.getCrossReq().getRecallUserId());
        builder.setOperation(reqMsg.getCrossReq().getOperation());
        builder.setRet(0);
        UserBaseInfo baseInfo = UserMgr.getUserBaseInfo(reqMsg.getCrossReq().getRecallUserId(), reqMsg.getCrossReq().getRecallUserServer());
        if (baseInfo == null) {
            builder.setRet(GameErrorCode.E_RECALL_PLAYER_NO_FIND_USER);
        } else {
            builder.setUserInfo(PlayerBasePb.parsePlayerBaseTempMsg(baseInfo));
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_PLAYER_RECALL_UPDATE_RETURN_USER_INFO_RESP, builder);
        GamePlayerMgr.sendPacket(0, message);
    }

}
